package com.kezesong.leasing.controller;

import com.kezesong.leasing.common.CacheService;
import com.kezesong.leasing.common.Constant;
import com.kezesong.leasing.common.CookieUtils;
import com.kezesong.leasing.common.ResponseResult;
import com.kezesong.leasing.controller.request.UserMsgInfoReq;
import com.kezesong.leasing.dto.SessionInfo;
import com.kezesong.leasing.entity.MsgInfoEntity;
import com.kezesong.leasing.service.MsgInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.concurrent.ExecutionException;

@RestController
@RequestMapping("/page")
public class MsgInfoController extends BaseController {

    @Autowired
    MsgInfoService msgInfoService;

    @PostMapping("/getUserMsgInfoList.do")
    @ApiOperation(value = "getUserMsgInfoList.do", notes = "获取用户消息列表")
    public ResponseResult<List<MsgInfoEntity>> getUserMsgInfoList(@RequestBody UserMsgInfoReq requestBody, HttpServletRequest request) throws ExecutionException {
       String sessionId = CookieUtils.getCookie(Constant.WEIXIN_SESSION_TICKET, request);
        SessionInfo userLoginInfo = CacheService.getUserLoginInfo(sessionId);
        String openId = null;
        if (null != userLoginInfo ) {
           openId = userLoginInfo.getOpenId();
       }
        MsgInfoEntity msgInfoEntity = new MsgInfoEntity();
        msgInfoEntity.setOpenId(openId);
        List<MsgInfoEntity> msgInfoList = msgInfoService.getMsgInfoList(msgInfoEntity);
        ResponseResult<List<MsgInfoEntity>> responseResult = buildSucessResponse(msgInfoList);
        return responseResult;
    }






}
